const pkg = require('./package');
const CompressionWebpackPlugin = require('compression-webpack-plugin');

const BASE_URL = '';

process.env.BASE_URL = BASE_URL;
process.env.VUE_APP_VERSION = pkg.version;
process.env.VUE_APP_NAME = pkg.name;

const IS_PROD = [ 'production', 'prod' ].includes(process.env.NODE_ENV);
const productionGzipExtensions = /\.(js|css|json|txt|html|ico|svg)(\?.*)?$/i;
module.exports = {
	publicPath: BASE_URL,
	productionSourceMap: false,
	outputDir: 'dist',

	pages: {
		index: {
			entry: 'src/index.js',
			template: 'public/index.html',
			filename: 'index.html',
			title: pkg.title
		}
	},
	devServer: {
		disableHostCheck: true
	},
	configureWebpack: (config) => {
		if (IS_PROD) {
			const plugins = [];
			plugins.push(
				new CompressionWebpackPlugin({
					filename: '[path].gz[query]',
					algorithm: 'gzip',
					test: productionGzipExtensions,
					threshold: 10240,
					minRatio: 0.8
				})
			);
			config.plugins = [ ...config.plugins, ...plugins ];
		}
	}
};
